﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【换绳】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto换绳
    /// </summary>
    public abstract class AutoChangeWireropeMapping : BaseMapping<ChangeWirerope, ChangeWireropeModel, ChangeWireropeFilterModel>
    {
        public AutoChangeWireropeMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override ChangeWireropeModel Entity2Model(ChangeWirerope entity)
        {
            ChangeWireropeModel model = new ChangeWireropeModel();

            model.ChangeWireropeID = entity.ChangeWireropeID;
            model.GroupInfoID = entity.GroupInfoID;
            model.Code = entity.Code;
            model.OldUsingWireropeID = entity.OldUsingWireropeID;
            model.OldCode = entity.OldCode;
            model.OldName = entity.OldName;
            model.NewUsingWireropeID = entity.NewUsingWireropeID;
            model.NewCode = entity.NewCode;
            model.NewName = entity.NewName;
            model.Reason = entity.Reason;
            model.InstallDate = entity.InstallDate;
            model.CreateUserID = entity.CreateUserID;
            model.CreateUserName = entity.CreateUserName;
            model.CreateDate = entity.CreateDate;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override ChangeWirerope Model2Entity(ChangeWireropeModel model)
        {
            ChangeWirerope entity = new ChangeWirerope();

            entity.ChangeWireropeID = model.ChangeWireropeID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.Code = model.Code;
            entity.OldUsingWireropeID = model.OldUsingWireropeID;
            entity.OldCode = model.OldCode;
            entity.OldName = model.OldName;
            entity.NewUsingWireropeID = model.NewUsingWireropeID;
            entity.NewCode = model.NewCode;
            entity.NewName = model.NewName;
            entity.Reason = model.Reason;
            entity.InstallDate = model.InstallDate;
            entity.CreateUserID = model.CreateUserID;
            entity.CreateUserName = model.CreateUserName;
            entity.CreateDate = model.CreateDate;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<ChangeWirerope> FilterModel2Where(ChangeWireropeFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._ChangeWireropeID.HasValue)
            {
                where = where.And(x => x.ChangeWireropeID == filterModel._ChangeWireropeID.Value);
            }
            if (filterModel._ChangeWireropeIDs.IsNotEmpty() && filterModel._ChangeWireropeIDs.Count > 0)
            {
                where = where.And(x => filterModel._ChangeWireropeIDs.Contains(x.ChangeWireropeID));
            }
            if (filterModel._NotChangeWireropeIDs.IsNotEmpty() && filterModel._NotChangeWireropeIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotChangeWireropeIDs.Contains(x.ChangeWireropeID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //编码
            if (!string.IsNullOrEmpty(filterModel._Code))
            {
                where = where.And(x => x.Code.Contains(filterModel._Code));
            }
            if (!string.IsNullOrEmpty(filterModel._CodeEqual))
            {
                where = where.And(x => x.Code == filterModel._CodeEqual);
            }

            //旧绳
            if (filterModel._OldUsingWireropeID.HasValue)
            {
                where = where.And(x => x.OldUsingWireropeID == filterModel._OldUsingWireropeID.Value);
            }
            if (filterModel._OldUsingWireropeIDs.IsNotEmpty() && filterModel._OldUsingWireropeIDs.Count > 0)
            {
                where = where.And(x => filterModel._OldUsingWireropeIDs.Contains(x.OldUsingWireropeID));
            }
            if (filterModel._NotOldUsingWireropeIDs.IsNotEmpty() && filterModel._NotOldUsingWireropeIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotOldUsingWireropeIDs.Contains(x.OldUsingWireropeID));
            }

            //旧绳编码
            if (!string.IsNullOrEmpty(filterModel._OldCode))
            {
                where = where.And(x => x.OldCode.Contains(filterModel._OldCode));
            }
            if (!string.IsNullOrEmpty(filterModel._OldCodeEqual))
            {
                where = where.And(x => x.OldCode == filterModel._OldCodeEqual);
            }

            //旧绳名称
            if (!string.IsNullOrEmpty(filterModel._OldName))
            {
                where = where.And(x => x.OldName.Contains(filterModel._OldName));
            }
            if (!string.IsNullOrEmpty(filterModel._OldNameEqual))
            {
                where = where.And(x => x.OldName == filterModel._OldNameEqual);
            }

            //新绳
            if (filterModel._NewUsingWireropeID.HasValue)
            {
                where = where.And(x => x.NewUsingWireropeID == filterModel._NewUsingWireropeID.Value);
            }
            if (filterModel._NewUsingWireropeIDs.IsNotEmpty() && filterModel._NewUsingWireropeIDs.Count > 0)
            {
                where = where.And(x => filterModel._NewUsingWireropeIDs.Contains(x.NewUsingWireropeID));
            }
            if (filterModel._NotNewUsingWireropeIDs.IsNotEmpty() && filterModel._NotNewUsingWireropeIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotNewUsingWireropeIDs.Contains(x.NewUsingWireropeID));
            }

            //新绳编码
            if (!string.IsNullOrEmpty(filterModel._NewCode))
            {
                where = where.And(x => x.NewCode.Contains(filterModel._NewCode));
            }
            if (!string.IsNullOrEmpty(filterModel._NewCodeEqual))
            {
                where = where.And(x => x.NewCode == filterModel._NewCodeEqual);
            }

            //新绳名称
            if (!string.IsNullOrEmpty(filterModel._NewName))
            {
                where = where.And(x => x.NewName.Contains(filterModel._NewName));
            }
            if (!string.IsNullOrEmpty(filterModel._NewNameEqual))
            {
                where = where.And(x => x.NewName == filterModel._NewNameEqual);
            }

            //安装日期
            if (filterModel._InstallDate.HasValue)
            {
                where = where.And(x => x.InstallDate == filterModel._InstallDate.Value);
            }
            if (filterModel._InstallDate_Begin.HasValue)
            {
                where = where.And(x => x.InstallDate >= filterModel._InstallDate_Begin.Value);
            }
            if (filterModel._InstallDate_End.HasValue)
            {
                where = where.And(x => x.InstallDate < filterModel._InstallDate_End.Value.AddDays(1));
            }

            //创建人姓名
            if (!string.IsNullOrEmpty(filterModel._CreateUserName))
            {
                where = where.And(x => x.CreateUserName.Contains(filterModel._CreateUserName));
            }
            if (!string.IsNullOrEmpty(filterModel._CreateUserNameEqual))
            {
                where = where.And(x => x.CreateUserName == filterModel._CreateUserNameEqual);
            }

            //创建时间
            if (filterModel._CreateDate.HasValue)
            {
                where = where.And(x => x.CreateDate == filterModel._CreateDate.Value);
            }
            if (filterModel._CreateDate_Begin.HasValue)
            {
                where = where.And(x => x.CreateDate >= filterModel._CreateDate_Begin.Value);
            }
            if (filterModel._CreateDate_End.HasValue)
            {
                where = where.And(x => x.CreateDate < filterModel._CreateDate_End.Value.AddDays(1));
            }

            return where;
        }
        #endregion
    }
}

